﻿<%@ Page Title="" Language="C#" MasterPageFile="~/forumMaster.Master" AutoEventWireup="true" CodeBehind="AdminArea.aspx.cs" Inherits="forum.AdminArea" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
  <script type="text/javascript">
      var threadToUpdate;
      $(document).ready(function () {
          $("#lnkbtnAddSubForum").click(function () {
              $("#txtForumNameAddSubForumPopApp").val("");
              open($("#addSubForumPopUp"));
              return false;
          });


          $("#addSubForumPopUp").dialog({
              autoOpen: false,
              title: "Add sub forum",
              modal: true,
              buttons: {
                  "ok": function () {

                      var parameters;
                      var forumName = $("#txtForumNameAddSubForumPopApp").val();
                      if (forumName != "") {
                          parameters = "{'forumName':'" + forumName + "'}";
                          $.ajax({
                              type: "POST",
                              url: "../Ajax/forumAjax.asmx/updateAddForumSession",
                              contentType: "application/json; charset=utf-8",
                              data: parameters,
                              success: function (result) {
                                  if (result.d != "bad") {
                                      location.reload();
                                      return false;
                                  }
                              },
                              error: function () {
                                  return false;
                              }
                          });
                      }
                      else {
                          alert("Please enter a name");
                          return false;
                      }
                      $(this).dialog("close");
                      return false;
                  },
                  "cancel": function () {
                      $(this).dialog("close");
                  }
              }
          });



          $("#lnkbtnDeleteSubForum").click(function () {
              open($("#deleteSubForumPopUp"));
              return false;
          });


          $("#deleteSubForumPopUp").dialog({
              autoOpen: false,
              title: "Delete sub forum",
              modal: true,
              buttons: {
                  "ok": function () {
                      var forumId = $("#ddlSubForumDeletePopUp").val();
                      if (forumId != '0') {
                          if (confirm("Delete Sub forum?")) {
                              var parameters;
                              parameters = "{'forumId':'" + forumId + "'}";
                              $.ajax({
                                  type: "POST",
                                  url: "../Ajax/forumAjax.asmx/deleteSubForum",
                                  contentType: "application/json; charset=utf-8",
                                  data: parameters,
                                  success: function (result) {
                                      if (result.d != "bad") {
                                          location.reload();
                                          return false;
                                      }
                                  },
                                  error: function () {
                                      return false;
                                  }
                              });
                          }
                          return false;
                      }
                      return false;
                      $(this).dialog("close");
                      return false;
                  },
                  "cancel": function () {
                      $(this).dialog("close");
                  }
              }
          });




          $("#lnkbtnRemoveModerator").click(function () {
              open($("#removeModeratorPopUp"));
              return false;
          });


          $("#ddlSubForum").change(function () {
              parameters = "{'subForumName':'" + $("#ddlSubForum option:selected").text() + "'}";
              $.ajax({
                  type: "POST",
                  url: "../Ajax/forumAjax.asmx/getModeratorsBySubForum",
                  contentType: "application/json; charset=utf-8",
                  data: parameters,
                  dataType: "json",
                  success: function (result) {
                      $("#ddlModerators").html(result.d);
                  },
                  error: function () {
                      return false;
                  }
              });
          });






          $("#removeModeratorPopUp").dialog({
              autoOpen: false,
              title: "Remove moderator",
              modal: true,
              buttons: {
                  "ok": function () {

                      var parameters;
                      var subForumId = $("#ddlSubForum").val();
                      var moderatorId = $("#ddlModerators").val();
                      var moderatorName = $("#ddlModerators option:selected").text();
                      if (moderatorId != "0") {
                          parameters = "{'subForumId':'" + subForumId + "','moderatorName': '" + moderatorName + "'}";
                          $.ajax({
                              type: "POST",
                              url: "../Ajax/forumAjax.asmx/removeModerator",
                              contentType: "application/json; charset=utf-8",
                              data: parameters,
                              success: function (result) {
                                  if (result.d != "bad") {
                                      location.reload();
                                      return false;
                                  }
                              },
                              error: function () {
                                  return false;
                              }
                          });
                      }
                      else {
                          alert("Please Choose Moderator");
                          return false;
                      }

                      $(this).dialog("close");
                      return false;
                  },
                  "cancel": function () {
                      $(this).dialog("close");
                  }
              }
          });

          $("#lnkbtnAddModerator").click(function () {
              open($("#addModeratorPopUp"));
              return false;
          });


          $("#ddlSubForumAdd").change(function () {
              parameters = "{'subForumName':'" + $("#ddlSubForumAdd option:selected").text() + "'}";
              $.ajax({
                  type: "POST",
                  url: "../Ajax/forumAjax.asmx/getSubForumModerateCandidates",
                  contentType: "application/json; charset=utf-8",
                  data: parameters,
                  dataType: "json",
                  success: function (result) {
                      $("#ddlUsers").html(result.d);
                  },
                  error: function () {
                      return false;
                  }
              });
          });

          $("#addModeratorPopUp").dialog({
              autoOpen: false,
              title: "Add moderator",
              modal: true,
              buttons: {
                  "ok": function () {

                      var parameters;
                      var subForumId = $("#ddlSubForumAdd").val();
                      var userId = $("#ddlUsers").val();
                      if (userId != "0") {
                          parameters = "{'subForumId':'" + subForumId + "','userId': '" + userId + "'}";
                          $.ajax({
                              type: "POST",
                              url: "../Ajax/forumAjax.asmx/AddModerator",
                              contentType: "application/json; charset=utf-8",
                              data: parameters,
                              success: function (result) {
                                  if (result.d != "bad") {
                                      location.reload();
                                      return false;
                                  }
                              },
                              error: function () {
                                  return false;
                              }
                          });
                      }
                      else {
                          alert("please choose a user");
                          return false;
                      }

                      $(this).dialog("close");
                      return false;
                  },
                  "cancel": function () {
                      $(this).dialog("close");
                  }
              }
          });


          $("#lnkbtnUserNumberMessages").click(function () {
              open($("#userMessagesPopUp"));
              return false;
          });


          $("#ddlUsersMessages").change(function () {
              parameters = "{'userName':'" + $("#ddlUsersMessages option:selected").text() + "'}";
              $.ajax({
                  type: "POST",
                  url: "../Ajax/forumAjax.asmx/getUserNumberOfMessages",
                  contentType: "application/json; charset=utf-8",
                  data: parameters,
                  dataType: "json",
                  success: function (result) {
                      alert(result.d);
                  },
                  error: function () {
                      return false;
                  }
              });
          });


          $("#lnkbtnTotalNumberMessages").click(function () {
              parameters = "{'srak':'" + "srak" + "'}";
              $.ajax({
                  type: "POST",
                  url: "../Ajax/forumAjax.asmx/getTotalMessages",
                  contentType: "application/json; charset=utf-8",
                  data: parameters,
                  dataType: "json",
                  success: function (result) {
                      alert(result.d);
                      return false;
                  },
                  error: function () {
                      return false;
                  }
              });
              return false;
          });


          $("#userMessagesPopUp").dialog({
              autoOpen: false,
              title: "User messages",
              modal: true,
              buttons: {
                  "ok": function () {
                      $(this).dialog("close");
                      return false;
                  },
                  "cancel": function () {
                      $(this).dialog("close");
                  }
              }
          });



          $("#lnkbtnChangeAdmin").click(function () {
              open($("#changeAdminPopUp"));
              return false;
          });

          $("#changeAdminPopUp").dialog({
              autoOpen: false,
              title: "Change admin",
              modal: true,
              buttons: {
                  "ok": function () {

                      var parameters;
                      var userId = $("#ddlNewAdmin").val();
                      if (userId != "0") {
                          parameters = "{'userId':'" + userId + "'}";
                          $.ajax({
                              type: "POST",
                              url: "../Ajax/forumAjax.asmx/changeAdmin",
                              contentType: "application/json; charset=utf-8",
                              data: parameters,
                              success: function (result) {
                                  if (result.d != "bad") {
                                      location.reload();
                                      return false;
                                  }
                              },
                              error: function () {
                                  return false;
                              }
                          });
                      }
                      else {
                          alert("please choose a user");
                          return false;
                      }

                      $(this).dialog("close");
                      return false;
                  },
                  "cancel": function () {
                      $(this).dialog("close");
                  }
              }
          });


      });

      
      </script>

    <style type="text/css">
       
       #adminMenu li
       {
            margin-top:10px;  
       }
       
       .adminMenuItem
       {
           
          text-decoration:none;
       }
       
       .adminMenuItem:hover
       {
           
          text-decoration:underline;
       }


       
    </style>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<div id="adminMenu">
    <ul>
         <li><asp:LinkButton ID="lnkbtnAddSubForum" class="adminMenuItem" ClientIDMode="Static" runat="server">Add sub forum</asp:LinkButton></li>
         <li><asp:LinkButton ID="lnkbtnDeleteSubForum" class="adminMenuItem" ClientIDMode="Static" runat="server">Delete sub forum</asp:LinkButton></li>
         <li><asp:LinkButton ID="lnkbtnRemoveModerator" class="adminMenuItem" ClientIDMode="Static" runat="server">Remove moderator</asp:LinkButton></li>
         <li><asp:LinkButton ID="lnkbtnAddModerator" class="adminMenuItem" ClientIDMode="Static" runat="server">Add moderator</asp:LinkButton></li>
         <li><asp:LinkButton ID="lnkbtnTotalNumberMessages" class="adminMenuItem" ClientIDMode="Static" runat="server">Total number of messages</asp:LinkButton></li>
         <li><asp:LinkButton ID="lnkbtnUserNumberMessages" class="adminMenuItem" ClientIDMode="Static" runat="server">Total messages by user</asp:LinkButton></li>
           <li><asp:LinkButton ID="lnkbtnChangeAdmin" class="adminMenuItem" ClientIDMode="Static" runat="server">Change admin</asp:LinkButton></li>
    </ul>
</div>



<div id="deleteSubForumPopUp">
      
        <asp:Label ID="lblSubForumNameDeletePopUp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="Choose forum"></asp:Label>
        <asp:DropDownList ID="ddlSubForumDeletePopUp" ClientIDMode="Static" runat="server"></asp:DropDownList>
</div>

<div id="removeModeratorPopUp">
      
        <asp:Label ID="lblSubForumRemoveModeratorPopUp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="Choose forum"></asp:Label>
        <asp:DropDownList ID="ddlSubForum" ClientIDMode="Static" runat="server"></asp:DropDownList>
        <asp:Label ID="lblModeratorRemoveModeratorPopUp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="Choose Moderator"></asp:Label>
        <asp:DropDownList ID="ddlModerators" ClientIDMode="Static" runat="server"></asp:DropDownList>
</div>


<div id="addModeratorPopUp">
       
        <asp:Label ID="lblSubForumAddModeratorPopUp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="Choose forum"></asp:Label>
        <asp:DropDownList ID="ddlSubForumAdd" ClientIDMode="Static" runat="server"></asp:DropDownList>
        <asp:Label ID="lblModeratorAddModeratorPopUp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="Choose User"></asp:Label>
        <asp:DropDownList ID="ddlUsers" ClientIDMode="Static" runat="server"></asp:DropDownList>
</div>


<div id="addSubForumPopUp">
       
        <asp:Label ID="lblForumNameAddSubForumPopApp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="Forum name"></asp:Label>
        <asp:TextBox ID="txtForumNameAddSubForumPopApp" ClientIDMode="Static"  runat="server"></asp:TextBox>
</div>

<div id="userMessagesPopUp">
      
        <asp:Label ID="lblUserNameMessagesPopUp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="UserName"></asp:Label>
        <asp:DropDownList ID="ddlUsersMessages" ClientIDMode="Static" runat="server"></asp:DropDownList>
</div>

<div id="changeAdminPopUp">
      
        <asp:Label ID="lblchangeAdminPopUp" class="popUpTitle" ClientIDMode="Static" runat="server" Text="UserName"></asp:Label>
        <asp:DropDownList ID="ddlNewAdmin" ClientIDMode="Static" runat="server"></asp:DropDownList>
</div>

</asp:Content>
